package com.nannybear.Model;

import java.util.ArrayList;
import java.util.Observer;

/**
 * @brief Own the modifiable thresholds of sound. Observable by ProxyRobot.
 */
public class SoundThreshold extends Constant{
    /********** DECLARATIONS **********/
    private int valueSound;
    private ArrayList<Observer> observers;

    /************ METHODS ************/
    /**
     * @brief constructor
     */
    public SoundThreshold(){
        //TODO : recuperer les valeurs écrites en dur
        valueSound = 0;
        this.observers = new ArrayList<>();
    }

    /**
     * @brief add the class as observable
     */
    public void addObserver(Observer obs){
        observers.add(obs);
    }

    /**
     * @brief delete the class as observable
     */
    public synchronized void deleteObserver(Observer obs){
        observers.remove(obs);
    }

    /**
     * @brief notify the observers
     */
    public void notifyObservers(){
        for (int i = 0; i < observers.size(); i++) {
            observers.get(i).update(this, this.valueSound);
        }
    }

    /*********** ACCESSORS ***********/
    public int getValueSound() {
        return valueSound;
    }

    public void setValueSound(int valueSound) {
        this.valueSound = valueSound;
        notifyObservers();
    }
}
